#include <math.h>
#include <vector>
#include <iostream>
#include "sensor.h"

using namespace std;

sensor::sensor(int ID, int datRate, float maxb, double maxr, float xpos, float ypos, int snk)
{
    id = ID;
    dataRate = datRate;
    x = xpos;
    y = ypos;
    battery = maxb;
    maxRange = maxr;
    sink = snk;
}

//s is vector of all sensors
void sensor::getNeighbor(vector<sensor> &s)
{
    double distance;
    neighbor.clear();

    for(int i=0;i < s.size(); i++)
    {
        // find distance
        distance = s[i].distance(x, y);

        // add to vector neighbor if a sensor is in 2*maxRange
        if ((distance <= 2*maxRange) && (distance != 0))
        {
            neighbor.push_back(&s[i]);
        }
    }
}

double sensor::distance(double x1, double y1)
{
    return sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
}
